import { createRouter, createWebHistory, createWebHashHistory } from 'vue-router'
import Home from '../views/home.vue'
import blank1 from '../views/crud/blank.vue'

const routes = [
  {
    path: '/',
    name: 'home',
    meta: { title: '首页' },
    component: Home
  },
  {
    path: '/base',
    name: 'base',
    meta: { title: '基础控件' },
    component: () => import('../views/baseControl.vue')
  },
  {
    path: '/form',
    name: 'form',
    meta: { title: '表单控件' },
    component: () => import('../views/form.vue')
  },
  {
    path: '/find',
    name: 'find',
    meta: { title: '查询控件' },
    component: () => import('../views/find.vue')
  },
  {
    path: '/grid',
    name: 'grid',
    meta: { title: '列表控件' },
    component: () => import('../views/grid.vue')
  },
  {
    path: '/crud',
    name: 'crud',
    meta: { title: '增删改查' },
    component: () => import('../views/crud/index.vue'),
    children: [
      {
        path: ':moduleId', // 通用的增删改查
        name: 'crud-list',
        meta: { title: '列表页面-' },
        props: true,
        // component: () => import('../views/crud/list.vue')
        components: {
          default: blank1, // 占位
          // 共用功能
          listshell: () => import('../views/crud/list-shell.vue')
        }
      },
      {
        path: 'module', // 通用的增删改查
        name: 'crud-module',
        meta: { title: '模块信息-' },
        props: true,
        components: {
          default: blank1, // 占位
          listshell: () => import('../views/crud/list-tree.vue')
        }
      },
      {
        path: 'base', // 其他的增删改查
        name: 'crud-base',
        meta: { title: '基础控件-' },
        props: true,
        // component: () => import('../views/baseControl.vue')
        components: {
          default: () => import('../views/baseControl.vue'), // 其他模块
          // 共用功能，占位
          listshell: () => import('../views/crud/list-shell.vue')
        }
      }
    ]
  },
  {
    path: '/plat',
    name: 'plat',
    meta: { title: '增删改查' },
    component: () => import('../views/plat/index.vue'),
    children: [
      {
        path: ':moduleId', // 通用的增删改查
        name: 'plat-list',
        meta: { title: '列表页面-' },
        props: true,
        component: () => import('../views/plat/base-page/list-shell.vue')
      },
      {
        path: 'module', // 通用的增删改查
        name: 'plat-module',
        meta: { title: '模块信息-' },
        props: true,
        component: () => import('../views/plat/base-page/list-tree.vue')
      },
      {
        path: 'baseset',
        meta: { title: '基础设置-' },
        name: 'plat-baseset',
        component: () => import('../views/plat/plat-baseset/index.vue')
      },
      {
        path: 'excel',
        meta: { title: 'excel文档-' },
        name: 'plat-excel',
        component: () => import('../views/plat/excel.vue')
      }
    ]
  },
  {
    path: '/tocol',
    name: 'tocol',
    meta: { title: '行列转换' },
    component: () => import('../views/tocol.vue')
  }
]

const router = createRouter({
  history: createWebHistory(),
  // history: createWebHistory(),
  // base: '/blog/',
  routes
})

// console.log('hist', createWebHistory())
// console.log('hash', createWebHashHistory())

router.beforeEach((to, from) => {
  // ...
  // 返回 false 以取消导航
  // console.log('全局路由——to：', to)
  document.title = ''

  to.matched.forEach((item) => {
    document.title = item.meta.title + document.title
  })
  // console.log('全局路由——from：', from)
  return true
})

// 添加动态路由
// router.addRoute({ path: '/about22', component: Home })

// console.log('创建路由——————', router)
export default router
